package com.zh.device.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zh.analysis.service.XiaoMiService;
import com.zh.device.service.BehaviorService;
import com.zh.device.service.DeviceService;
import com.zh.analysis.service.MeasureService;
import com.zh.device.service.RedisDeviceService;
import com.zh.device.util.DeviceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeviceServiceImpl implements DeviceService {


    @Autowired
    private RedisDeviceService redisDeviceService;

    @Autowired
    private MeasureService measureService;

    @Autowired
    private BehaviorService behaviorService;

    @Autowired
    private XiaoMiService xiaoMiService;

    @Override
    public void deviceProsson(JSONObject jsonParam) throws Exception{
        String deviceType=jsonParam.getString("deviceType");
        String deviceSn=jsonParam.getString("deviceSn");
        String remark=jsonParam.getString("Remark");
        JSONObject dataJSON=null;

        System.out.println("@@设备启动时间："+DeviceUtil.formatCreateDate(jsonParam.getString("timeCreate")));
        if("XiaoMi".equals(deviceType)){
            //TODO 小米几乎都智能感知设备 需要根据设备id 查看设备类型根据设备类型判断
            dataJSON=xiaoMiService.todoDeviceByXiaoMi(jsonParam,deviceSn);
            redisDeviceService.prossonDevice(1,dataJSON,deviceSn);
        }
        if("RFID_Tag".equals(deviceType)){
            //todo 需要根据网关id  判断当前的网关行为
            String gatewayId=jsonParam.getString("gatewayId");

        }

        if(!"".equals(remark)){//老人刷卡进行体征检测

        }

        if("Thermometer".equals(deviceType)){//耳温枪
            dataJSON=measureService.thermometer(jsonParam.getString("deviceData"));
            dataJSON.put("timeCreate",jsonParam.getString("timeCreate"));
            redisDeviceService.prossonDevice(0,dataJSON,deviceSn);
            //todo 查询绑定关系 建立websocket链接
        }if("Oximeter".equals(deviceType)){//血氧
            dataJSON=measureService.oximeter(jsonParam.getString("deviceData"));
            dataJSON.put("timeCreate",jsonParam.getString("timeCreate"));
            redisDeviceService.prossonDevice(0,dataJSON,deviceSn);
            //todo 查询绑定关系 建立websocket链接
        }if("Sphygmomanometer".equals(deviceType)){//血压
            dataJSON=measureService.sphygmomanometer(jsonParam.getString("deviceData"));
            dataJSON.put("timeCreate",jsonParam.getString("timeCreate"));
            redisDeviceService.prossonDevice(0,dataJSON,deviceSn);
            //todo 查询绑定关系 建立websocket链接
        }

    }


}
